var mainApp = angular.module("mainApp", ["angular-popups", "mainFilter", "scService", "ui.router", "loginApp", "userInfoApp", "myOrderApp", "orderPayApp", "orderPayDetailApp", "orderDetailApp", "chargeStarted", "charging", "appointingApp", "manualCode", "searchApp", "searchResultApp", "noResult"]);
mainApp.run(function($rootScope, $stateParams, $timeout, $state, $location, $window) {
    //定义显示title
    $rootScope.mainTitle = '';
    //页面加载完后执行
    $rootScope.$on('$stateChangeSuccess', function(event, toState, next, previous) {
        //定义显示title
        $rootScope.mainTitle = toState.title;
    });
});
mainApp.config(function($urlRouterProvider, $stateProvider, $locationProvider) {
    $stateProvider
        .state("index_", {
            title: "电桩",
            url: "/index_",
            templateUrl: "index_.html",
            controller: "indexController"
        })
        .state("orderPay", {
            title: "订单详情",
            url: "/orderPay/:orderNo",
            templateUrl: "assets/scripts/app/orderPay/views/orderPay.html"
        })
        .state("paySuccess", {
            url: "/paySuccess/:orderNo",
            templateUrl: "assets/scripts/app/orderPay/views/paySuccess.html"
        })
        .state("payFail", {
            url: "/payFail/:orderNo",
            templateUrl: "assets/scripts/app/orderPay/views/payFail.html"
        })
        .state("orderPayDetail", {
            title: "费用明细",
            url: "/orderPayDetail/:orderNo",
            templateUrl: "assets/scripts/app/orderPay/views/orderPayDetail.html"
        })
        .state("orderDetail", {
            title: "订单详情",
            url: "/orderDetail/:orderNo",
            templateUrl: "assets/scripts/app/orderPay/views/orderDetail.html"
        })
        .state("login", {
            url: "/login/:code",
            templateUrl: "assets/scripts/app/login/views/login.html"
        })
        .state("userInfo", {
            title: "个人中心",
            url: "/userInfo",
            templateUrl: "assets/scripts/app/userInfo/views/userInfo.html"
        })
        .state("myCollect", {
            title: "我的收藏",
            url: "/myCollect",
            templateUrl: "assets/scripts/app/userInfo/views/myCollect.html"
        })
        .state("operation", {
            title: "操作指引",
            url: "/operation",
            templateUrl: "assets/scripts/app/userInfo/views/operation.html"
        })
        .state("myOrder", {
            title: "我的订单",
            url: "/myOrder",
            templateUrl: "assets/scripts/app/myOrder/views/myOrder.html"
        })
        /* .state("myOrder.pending", {
             url: "/pending",
             templateUrl: "assets/scripts/app/myOrder/views/pending.html"
         })
         .state("myOrder.processing", {
             url: "/processing",
             templateUrl: "assets/scripts/app/myOrder/views/processing.html"
         })
         .state("myOrder.over", {
             url: "/over",
             templateUrl: "assets/scripts/app/myOrder/views/over.html"
         })*/
        .state("evaluation", {
            title: "订单详情",
            url: "/evaluation/:orderNo",
            templateUrl: "assets/scripts/app/orderPay/views/evaluation.html"
        })
        .state("notPay", {
            url: "/notPay/:carNo",
            templateUrl: "assets/scripts/app/login/views/notPay.html"
        })
        // 扫码充电部分
        .state("chargeStarted", {
            title: "充电",
            url: "/chargeStarted",
            templateUrl: "assets/scripts/app/scanCharging/views/chargeStarted.html",
            controller: "chargeStartedController"
        })
        .state("charging", {
            title: "充电中",
            url: "/charging/:chargeSn",
            templateUrl: "assets/scripts/app/scanCharging/views/charging.html",
            controller: "chargingController"
        })
        .state("manualCode", {
            url: "/manualCode",
            templateUrl: "assets/scripts/app/scanCharging/views/manualCode.html",
            controller: "againScanController"
        })
        .state("errorScan", {
            title: "充电",
            url: "/errorScan",
            template: '<div class="mc-ct"><div class="mc-pic"><img src="assets/images/Icon_error@2x.png" alt=""><p class="fs18 color666 t-b">请扫描充电桩上二维码</p></div></div>'
        })
        .state("legal", {
            title: "用户服务协议",
            url: "/legal",
            templateUrl: "assets/scripts/app/login/views/legal.html",
            controller: "loginController"
        })
        .state("search", {
            title: "电桩",
            url: "/search/:currentId",
            templateUrl: "assets/scripts/app/search/views/search.html",
            controller: "searchController"
        })
        .state("checkCity", {
            title: "选择城市",
            url: "/checkCity",
            templateUrl: "assets/scripts/app/search/views/checkCity.html",
            controller: "checkCityController"
        })
        .state("searchResult", {
            title: "电桩",
            url: "/searchResult",
            templateUrl: "assets/scripts/app/search/views/searchResult.html",
            controller: "searchResultController"
        })
        .state("beAppointing", { //开始预约
            title: "预约",
            url: "/beAppointing/:chargerId",
            templateUrl: "assets/scripts/app/appointment/views/beAppointing.html",
            controller: "beAppointingController"
        })
        .state("appointing", { //预约中
            title: "预约中",
            url: "/appointing/:appointingId",
            templateUrl: "assets/scripts/app/appointment/views/appointing.html",
            controller: "appointingController"
        })
        .state("station", { //站点
            url: "/station",
            templateUrl: "assets/scripts/app/station/stationList.html"
                // controller:""
        })
        .state("station.pilePosition", {
            url: "/pilePosition",
            templateUrl: "assets/scripts/app/station/pilePosition.html"
        })
        .state("station.stationDetails", {
            url: "/stationDetails",
            templateUrl: "assets/scripts/app/station/stationDetails.html"
        })
        .state("stateDetail", {
            title: "站点详情",
            url: "/stateDetail/:stationId/:distance",
            templateUrl: "assets/scripts/app/appointment/views/stateDetail.html",
            controller: "stateDetailController"
        })
        .state("noResult", {
            title: "电桩",
            url: "/noResult/:searchName",
            templateUrl: "assets/scripts/app/search/views/noResult.html",
            controller: "noResultController"
        })

})

mainApp.controller('weuiCtrl', function($scope, $rootScope, scCodeService, $stateParams, $q, $timeout, $location, Popup, pubFun) {
    // document.addEventListener('touchmove', function(e) {
    //     e.preventDefault();
    // });
    $scope.wexLimit = function(){
        // 对浏览器的UserAgent进行正则匹配，不含有微信独有标识的则为其他浏览器
        var useragent = navigator.userAgent;
        if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
            // 这里警告框会阻塞当前页面继续加载
            alert('已禁止本次访问：您必须使用微信内置浏览器访问本页面！');
            // 以下代码是用javascript强行关闭当前页面
            var opened = window.open('about:blank', '_self');
            opened.opener = null;
            opened.close();
        }
    };
    $scope.wexLimit();
    $rootScope.showLogin = false;

    //confirm类型
    $scope.confirmSet = function(confirm) {
            var defailt_confirm = document.getElementById("defailt_confirm");
            defailt_confirm.style.display = "block";
            $scope.confirm = {
                title: confirm.title,
                content: confirm.content,
                button: confirm.button
            };
        }
        //Toast类型
    $scope.toastSet = function(toast) {
            var defailt_toast = document.getElementById("defailt_toast");
            defailt_toast.style.display = "block";
            $scope.toast = {
                content: toast.content,
                kind: toast.kind
            };
            setTimeout(function() {
                defailt_toast.style.display = "none";
            }, 2000);
        }
        // 退出登录
    $rootScope.showEx = false;
    $scope.setConfirmEx = function() {
            $rootScope.showEx = true;
        }
        // 双按钮confirm 退出确认退出
    $rootScope.showWeird = false;
    $scope.weirdConfirmSet = function(weirdConfirm) {
            $rootScope.showWeird = true;
            $scope.weirdConfirm = weirdConfirm;
        }
        //loading类型
    $scope.loadingToastSet = function(content) {
            var defailt_toast = document.getElementById("loadingToast");
            defailt_toast.style.display = "block";
            $scope.loadingToastContent = {
                content: content
            };
        }
        //隐藏loading
    $scope.loadingToastHide = function() {
            var defailt_toast = document.getElementById("loadingToast");
            defailt_toast.style.display = "none";
        }
        // 收藏、删除收藏（全局）
    $rootScope.collectionStation = function(stationId, type) {
        var cTime = new Date().getTime();
        $scope.forbidden = true;
        var isLogin = localStorage.getItem("isLogin");
        if (isLogin == "true") {
            var deferred = $q.defer();
            var postData = {
                stationId: stationId,
                userId: localStorage.getItem("userId")
            };
            //alert(JSON.stringify(postData));
            scCodeService.collectionStation(postData).then(function(data) {
                //alert(JSON.stringify(data));
                if (data.code == "200") {
                    var gTime = new Date().getTime();
                    // alert(gTime-cTime)
                    $scope.forbidden = false;
                    if (type == '1') {
                        $scope.toastSet({
                            content: "已取消收藏"
                        })
                    }
                    deferred.resolve();
                }
            });
            return deferred.promise;
        } else {
            localStorage.setItem("state", 3)
            $rootScope.showLogin = true;
        }

    };
    //点击进入预约界面
    $rootScope.goToAppointing = function(qrCode, reservationSn) {
            var postData = {
                qrCode: qrCode
            }
            scCodeService.getChargerDetailByQrCode(postData).then(function(data) {

                if (data.code == "200") {
                    if (data.data) {
                        $scope.chargerDetail = data.data;

                        //组装桩类型数据
                        if ($scope.chargerDetail.chargerType == "1") {
                            $scope.chargerDetailType = "直流 快充"
                        } else if ($scope.chargerDetail.chargerType == "2") {
                            $scope.chargerDetailType = "交流220V 慢充"
                        }
                        pubFun.getRate($scope.chargerDetail.chargerId).then(function(data) {
                            $scope.mainRate = data;
                            localStorage.setItem("chargerDetail", JSON.stringify($scope.chargerDetail));
                            localStorage.setItem("mainRate", JSON.stringify($scope.mainRate));
                            pubFun.getStationDetail($scope.chargerDetail.stationId).then(function(data) {
                                localStorage.setItem("latitude", data.latitude);
                                localStorage.setItem("longitude", data.longitude);
                                window.location.href = mainConfig.hostUrl + 'index.html#/appointing/' + reservationSn;
                            });
                        });
                    }
                } else {
                    Popup.notice('获取桩信息失败', 3000, function() {

                    });
                }
            })
        }
        //点击进入充电界面
    $rootScope.goToCharging = function(qrCode, chargeSn, startTime, startTimestr) {
        var postData = {
            qrCode: qrCode
        }
        scCodeService.getChargerDetailByQrCode(postData).then(function(data) {

            if (data.code == "200") {
                if (data.data) {
                    $scope.chargerDetail = data.data;

                    var temp = new Date();
                    var SMS = Date.parse(temp);
                    localStorage.setItem("SMS", startTime);

                    localStorage.setItem("startTime", startTimestr);
                    //判断充电开启状态
                    $scope.openCharge = "true";
                    localStorage.setItem("openCharge", $scope.openCharge);
                    localStorage.setItem("chargerDetail", JSON.stringify($scope.chargerDetail));
                    //chargerId and plugNo
                    localStorage.setItem("chargerId", $scope.chargerDetail.chargerId);
                    localStorage.setItem("plugNo", $scope.chargerDetail.plugNoList[0].portNo);
                    pubFun.getRate($scope.chargerDetail.chargerId).then(function(data) {
                        localStorage.setItem("rate", data.chargerRate);
                        window.location.href = mainConfig.hostUrl + 'index.html#/charging/' + chargeSn;
                    });

                }
            } else {
                Popup.notice('获取桩信息失败', 3000, function() {

                });
            }
        })

    };
    // confirm确定
    $rootScope.confirmSure = function(data) {
        $rootScope.showWeird = false;
        var token = localStorage.getItem("token");
        var userId = localStorage.getItem("userId");
        var postData = {
            source: mainConfig.source,
            merchantCode: mainConfig.merchantCode,
            token: token
        };
        //alert(JSON.stringify(postData))
        switch (data.type) {
            // 取消预约
            case "1":
                delete postData.chargeSn;
                $scope.loadingToastSet("取消预约中...");
                mainConfig.isNotPushFlag = true;
                postData.reservationSn = data.reservationSn;
                scCodeService.cancelReservation(postData).then(function(data) {
                    if (data.code == "200") {
                        var num = 0;
                        var pushTimeout = setInterval(function() {
                            num++;
                            if (num > mainConfig.overTimeSeconds && mainConfig.isNotPushFlag) {
                                clearInterval(pushTimeout);
                                var postData = {
                                    userId: userId,
                                    status: "0"
                                }
                                pubFun.getOngoingOperation().then(function(data) {
                                    if (globalFun.isEmptyObj(data.reservationList) == false) {
                                        $scope.loadingToastHide();
                                        Popup.notice('取消预约失败', 3000, function() {});
                                    } else {
                                        Popup.notice('取消预约成功', 3000, function() {});
                                        $rootScope.showWeird = false;
                                        $rootScope.isCancelReservation = false;
                                        $scope.loadingToastSet("订单推送中...");
                                        pubFun.getPending().then(function(orderdata) {
                                            $scope.loadingToastHide();
                                            if (globalFun.isEmptyObj(orderdata) == false) {
                                                window.location.href = mainConfig.hostUrl + "index.html?#/orderPay/" + orderdata[0].orderNo;
                                            } else {
                                                $location.path("/myOrder");
                                            }
                                        });
                                    }
                                });
                            }
                        }, 1000);
                    } else {
                        $scope.loadingToastHide();
                        $scope.toastSet({
                            content: "取消预约失败"
                        });
                    }
                });
                break;
            case "2":
                delete postData.reservationSn;
                $scope.loadingToastSet("结束充电中...");
                mainConfig.isNotPushFlag = true;
                postData.chargeSn = data.chargeSn;
                var plugStatusData = {
                    plugNo: data.portNo,
                    chargerId: data.chargerId
                }
                scCodeService.plugStatus(plugStatusData).then(function(data) {
                    if (data.code == "200") {
                        var currentChargeSn = data.data.chargeSn;
                        if (currentChargeSn != postData.chargeSn) {
                            $scope.loadingToastHide();
                            $scope.toastSet({
                                content: "充电桩停止充电失败"
                            });
                        } else {
                            scCodeService.closeCharge(postData).then(function(data) {
                                if (data.code == "200") {
                                    var num = 0;
                                    var pushTimeout = setInterval(function() {
                                        num++;
                                        if (num > mainConfig.overTimeSeconds && mainConfig.isNotPushFlag) {
                                            clearInterval(pushTimeout);
                                            var postData = {
                                                userId: userId,
                                                status: "0"
                                            }
                                            pubFun.getOngoingOperation().then(function(data) {
                                                if (globalFun.isEmptyObj(data.chargeList) == false) {
                                                    $scope.loadingToastHide();
                                                    Popup.notice('充电桩停止充电失败', 3000, function() {

                                                    });
                                                } else {
                                                    Popup.notice('充电桩停止充电成功', 3000, function() {

                                                    });
                                                    $rootScope.showWeird = false;
                                                    $scope.loadingToastSet("订单推送中...");
                                                    pubFun.getPending().then(function(orderdata) {
                                                        $scope.loadingToastHide();
                                                        if (globalFun.isEmptyObj(orderdata) == false) {
                                                            window.location.href = mainConfig.hostUrl + "index.html?#/orderPay/" + orderdata[0].orderNo;
                                                        } else {
                                                            $location.path("/myOrder");
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }, 1000);
                                } else {
                                    $scope.loadingToastHide();
                                    $scope.toastSet({
                                        content: "充电桩停止充电失败"
                                    });
                                }
                            });
                        }

                    } else {
                        $scope.loadingToastHide();
                        $scope.toastSet({
                            content: "充电桩停止充电失败"
                        });
                    }

                });
                break;
            case "3":
                $rootScope.showWeird = false;
                window.location.href = mainConfig.hostUrl + "index.html?#/orderPay/" + data.orderNo;
                break;
            case "4":
                $rootScope.showWeird = false;
                var qrCode = data.msg.chargerDetail.qrCode,
                    startTime = data.msg.startTime,
                    startTimestr = globalFun.timeToNrm(startTime),
                    chargeSn = data.msg.chargeSn;
                $rootScope.goToCharging(qrCode, chargeSn, startTime, startTimestr);
                break;
            case "5":
                $rootScope.showWeird = false;
                var qrCode = data.msg.chargerDetail.qrCode,
                    reservationSn = data.msg.reservationSn;
                $rootScope.goToAppointing(qrCode, reservationSn);
                break;
        }

    };

});


// 首页控制器
mainApp.controller("indexController", function($scope, $rootScope, scCodeService, $stateParams, $q, $timeout, $location, pubFun) {
    $rootScope.pageTitle = "电桩";
    //alert("进入首页控制器")
    $scope.user = function(index) {
        var isLogin = localStorage.getItem("isLogin");
        if (isLogin == "true") {
            if (index == 1) {
                $location.path("userInfo")
            } else {
                $q.all([pubFun.getPending(), pubFun.getOngoingOperation()]).then(function(data) {
                    if (globalFun.isEmptyObj(data[0]) == false) {
                        var notPayCardNo = data[0][0].orderNo;
                        $scope.weirdConfirmSet({
                            title: "",
                            content: "你有一个未支付的订单",
                            buttonAux: '取消',
                            buttonMain: '立即支付',
                            icon: "pending",
                            data: { type: "3", orderNo: notPayCardNo } //type: "1"，取消预约 "2"，结束充电 "3"，有未支付 "4"，有充电业务 "5"，有充预约务
                        });
                    } else if (globalFun.isEmptyObj(data[1].chargeList) == false) {
                        $scope.weirdConfirmSet({
                            title: "",
                            content: "您有一项充电任务正在进行中",
                            buttonAux: '取消',
                            buttonMain: '去看看',
                            icon: "charge",
                            data: { type: '4', msg: data[1].chargeList[0] } //type: "1"，取消预约 "2"，结束充电 "3"，有未支付 "4"，有充电业务 "5"，有充预约务
                        });
                    } else if (globalFun.isEmptyObj(data[1].reservationList) == false) {
                        $scope.weirdConfirmSet({
                            title: "",
                            content: "您有一项预约订单正在进行中",
                            buttonAux: '取消',
                            buttonMain: '去看看',
                            icon: "book",
                            data: { type: '5', msg: data[1].reservationList[0] } //type: "1"，取消预约 "2"，结束充电 "3"，有未支付 "4"，有充电业务 "5"，有充预约务
                        });
                    } else {
                        window.location.href = mainConfig.hostUrl + "scanCode.html";
                    }
                })
            }
        } else {
            localStorage.setItem("state", index)
            $rootScope.showLogin = true;
        }
    };
    // 搜索
    $scope.search = function() {
        $scope.currentId = 1;
        document.getElementById("loadingToast1").style.display = "block";
        $location.path("search/" + $scope.currentId);

    };
    // 推荐周边
    $scope.recommend = function() {
        document.getElementById("loadingToast1").style.display = "block";
        $location.path("searchResult");
    };
    //获取微信签名

    //默认经纬度
    var coords = {
        latitude: globalFun.decimal(mainConfig.defaultLatitude, 6),
        longtitude: globalFun.decimal(mainConfig.defaultLongtitude, 6)
    }
    localStorage.setItem("coords", JSON.stringify(coords));
    // 获取经纬度
    $scope.getCoords = function() {
        var deferred = $q.defer();
        scCodeService.getJsSign().then(function(data) {
            //alert(datastr);
            if (data.code == "200") {
                var wxparams = data.data
                    //通过config接口注入权限验证配置
                wx.config({
                    debug: false,
                    appId: wxparams.appId,
                    timestamp: wxparams.timeStamp,
                    nonceStr: wxparams.nonceStr,
                    signature: wxparams.sign,
                    jsApiList: [
                        'checkJsApi',
                        'onMenuShareTimeline',
                        'onMenuShareAppMessage',
                        'onMenuShareQQ',
                        'onMenuShareWeibo',
                        'onMenuShareQZone',
                        'hideMenuItems',
                        'showMenuItems',
                        'hideAllNonBaseMenuItem',
                        'showAllNonBaseMenuItem',
                        'translateVoice',
                        'startRecord',
                        'stopRecord',
                        'onVoiceRecordEnd',
                        'playVoice',
                        'onVoicePlayEnd',
                        'pauseVoice',
                        'stopVoice',
                        'uploadVoice',
                        'downloadVoice',
                        'chooseImage',
                        'previewImage',
                        'uploadImage',
                        'downloadImage',
                        'getNetworkType',
                        'openLocation',
                        'getLocation',
                        'hideOptionMenu',
                        'showOptionMenu',
                        'closeWindow',
                        'scanQRCode',
                        'chooseWXPay',
                        'openProductSpecificView',
                        'addCard',
                        'chooseCard',
                        'openCard'
                    ]
                });
                wx.ready(function() {
                    //调用微信接口获取坐标
                    wx.getLocation({
                        type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                        success: function(res) {
                            var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                            var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                            var speed = res.speed; // 速度，以米/每秒计
                            var accuracy = res.accuracy; // 位置精度
                            var coords = {
                                latitude: globalFun.decimal(latitude, 6),
                                longtitude: globalFun.decimal(longitude, 6)
                            }
                            localStorage.setItem("coords", JSON.stringify(coords));
                            deferred.resolve(coords);
                        },
                        cancel: function() {
                            Popup.notice("无法获取当前位置，已默认成都市", 2000);
                            var coords = {
                                latitude: globalFun.decimal(mainConfig.defaultLatitude, 6),
                                longtitude: globalFun.decimal(mainConfig.defaultLongtitude, 6)
                            }
                            localStorage.setItem("coords", JSON.stringify(coords));
                            deferred.resolve(coords);
                        },
                        error: function() {
                            Popup.notice("无法获取当前位置，已默认成都市", 2000);
                            var coords = {
                                latitude: globalFun.decimal(mainConfig.defaultLatitude, 6),
                                longtitude: globalFun.decimal(mainConfig.defaultLongtitude, 6)
                            }
                            localStorage.setItem("coords", JSON.stringify(coords));
                            deferred.resolve(coords);
                        }
                    });
                });
            } else {
                var coords = {
                    latitude: globalFun.decimal(mainConfig.defaultLatitude, 6),
                    longtitude: globalFun.decimal(mainConfig.defaultLongtitude, 6)
                }
                localStorage.setItem("coords", JSON.stringify(coords));
                deferred.resolve(coords);
            }

        });
        return deferred.promise;
    };

    //进入首页执行的方法
    $scope.getCoords().then(function(data) {
        console.log("首页" + JSON.stringify(data));
        if (data == "" || data == null || data == undefined) {
            data = {
                latitude: globalFun.decimal(mainConfig.defaultLatitude, 6),
                longtitude: globalFun.decimal(mainConfig.defaultLongtitude, 6)
            }
        }
        var CoordData = {
            latitude: data.latitude,
            longtitude: data.longtitude,
            locaLatitude: data.latitude,
            locaLongtitude: data.longtitude
        }
        pubFun.getStationByCoordinate(CoordData);
        pubFun.getCityName(data);
    });
    pubFun.autoLogin().then(function(data) {
        return pubFun.getUserCard()
    }).then(function() {
        return $q.all([pubFun.getPending(), pubFun.getOngoingOperation()])
    }).then(function(data) {
        // data[0] = [{ orderNo: "dfdfd" }]
        if (globalFun.isEmptyObj(data[0]) == false) {
            var notPayCardNo = data[0][0].orderNo;
            $scope.weirdConfirmSet({
                title: "",
                content: "你有一个未支付的订单",
                buttonAux: '取消',
                buttonMain: '立即支付',
                icon: "pending",
                data: { type: "3", orderNo: notPayCardNo } //type: "1"，取消预约 "2"，结束充电 "3"，有未支付 "4"，有充电业务 "5"，有充预约务
            });
        } else if (globalFun.isEmptyObj(data[1].chargeList) == false) {
            $scope.openCharge = "true";
            localStorage.setItem("openCharge", $scope.openCharge);
            $scope.weirdConfirmSet({
                title: "",
                content: "您有一项充电任务正在进行中",
                buttonAux: '取消',
                buttonMain: '去看看',
                icon: "charge",
                data: { type: "4", msg: data[1].chargeList[0] } //type: "1"，取消预约 "2"，结束充电 "3"，有未支付 "4"，有充电业务 "5"，有充预约务
            });
        } else if (globalFun.isEmptyObj(data[1].reservationList) == false) {
            $scope.weirdConfirmSet({
                title: "",
                content: "您有一项预约订单正在进行中",
                buttonAux: '取消',
                buttonMain: '去看看',
                icon: "book",
                data: { type: "5", msg: data[1].reservationList[0] } //type: "1"，取消预约 "2"，结束充电 "3"，有未支付 "4"，有充电业务 "5"，有充预约务
            });
        } else {

        }
    });
})

// 渲染模版
mainApp.directive('confirm', function() {
    return {
        restrict: 'EA',
        templateUrl: 'assets/scripts/plugins/weui-angular/default_confirm.html',
        replace: true,
        link: function(scope) {
            scope.confirmHide = function() {
                var defailt_confirm = document.getElementById("defailt_confirm");
                defailt_confirm.style.display = "none";
            }
        }
    }
});
mainApp.directive('toast', function() {
    return {
        restrict: 'EA',
        templateUrl: 'assets/scripts/plugins/weui-angular/default_toast.html',
        replace: true
    }
});
//退出登录弹层指令
mainApp.directive('confirmEx', function($rootScope) {
    return {
        restrict: 'EA',
        templateUrl: 'assets/scripts/plugins/weui-angular/confirmEx.html',
        replace: true,
        link: function(scope) {
            scope.confirmExHide = function() {
                $rootScope.showEx = false;
            };
        }
    }
});
mainApp.directive('weirdConfirm', function($rootScope) {
    return {
        restrict: 'EA',
        templateUrl: 'assets/scripts/plugins/weui-angular/weird_confirm.html',
        replace: true,
        link: function(scope) {
            scope.weirdConfirmHide = function() {
                $rootScope.showWeird = false;
            }
        }
    }
});
